<?php
session_start();
if(isset($_SESSION['admin_id'])) {
    include('../include/dbFunctions.php');

    /*
 * function sanitizeColumnName($columnName)
 * With Plugin Requirement, column name of html table must be the same with column name in database
 * e.g. Column in database: 'volunteer_name' --> In HTML table can be: 'Volunteer Name'
    */
    function sanitizeColumnName($columnName) {
        $result = strtolower(trim(str_replace(" ", "_", $columnName)));
        return $result;
    }

    $table = "student";
    $id = $_POST['id']; //ID is the id inside the <TR> tag
    $updateValue = $_POST['value']; //What we updated
    $column = sanitizeColumnName($_POST['columnName']);

    $query = "UPDATE $table SET $column = '$updateValue' WHERE student_id = $id";
    $result = executeQuery($query);
    if ($result!=0) {
        echo $updateValue;
    }else {
        echo "Error!";
    }

    ?>
    <?php
}else {
    header("Location: ../include/login.html");
}
?>